<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<?php include(DDROOTPATH.'/cache/title/'.$pagetag.'_title.php');?>
<link href="template/<?=MOBAN?>/css/common.css" rel="stylesheet" />
<link href="template/<?=MOBAN?>/css/redirect.css" rel="stylesheet" type="text/css" />
<link href="template/<?=MOBAN?>/css/shai_l.css" rel="stylesheet" />

<script language="javascript" type="text/javascript" src="template/<?=MOBAN?>/js/jquery.js"></script>
<SCRIPT type="text/javascript" src="template/<?=MOBAN?>/js/base64.js"></SCRIPT>
<SCRIPT type="text/javascript" src="template/<?=MOBAN?>/js/function.js"></SCRIPT>
<script type="text/vbscript">
Function str2asc(strstr)
str2asc = hex(asc(strstr))
End Function
Function asc2str(ascasc)
asc2str = chr(ascasc)
End Function
</script>
<script language="JavaScript" type="text/javascript">
<!-- 
function imgAuto(img, maxW, maxH) {
	var oriImg = document.createElement("img");
	oriImg.onload = function(){
		if (oriImg.width == 0 || oriImg.height == 0)
			return;
		var oriW$H = oriImg.width / oriImg.height;
		// var maxW$H = maxW / maxH;

		if (oriImg.height > maxH) {
			img.height = maxH;
			// img.removeAttribute("width");
			img.width = maxH * oriW$H;
		}
		if (img.width > maxW) {
			img.width = maxW;
			// img.removeAttribute("height");
			img.height = maxW / oriW$H;
		}

		if (maxH) {// if it defined the maxH argument
			if (img.height > 0)
				img.style.marginTop = (maxH - img.height) / 2 + "px";
		}
	};
	oriImg.src = img.src;
}
//-->
commentDefaultVal='说说你对这件宝贝的评价吧';

function addExpression(myField, myValue)
{
    myField = document.getElementById(myField);
	if(myField.value==commentDefaultVal) myField.value='';
    //IE
    if (document.selection)
    {
        myField.focus();
        sel = document.selection.createRange();
        myValue = myValue;
        sel.text = myValue;
        sel.select();
    }
    //MOZILLA
    else if (myField.selectionStart || myField.selectionStart == '0')
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        // save scrollTop before insert
        var restoreTop = myField.scrollTop;
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos,myField.value.length);
        if (restoreTop > 0)
        {
            // restore previous scrollTop
            myField.scrollTop = restoreTop;
        }
        myField.focus();
        myField.selectionStart = startPos + myValue.length;
        myField.selectionEnd = startPos + myValue.length;
    }
    else
    {
        myField.value += myValue;
        myField.focus();
    }
}

$.ajaxSetup ({
    cache: false //关闭AJAX相应的缓存
});
msgErr=new Array();
msgErr[5]='您已经分享过这件商品';
msgErr[6]='您没有购买过商品，不能评论';
msgErr[7]='您提交的信息不全';
msgErr[8]='评论不能为空或者含有敏感词';
msgErr[9]='必须添加图片';
msgErr[15]='此商品已有人分享过，换换别的吧，O(∩_∩)O';

function closeShare(){
    $('.LightBox').hide();
	$('#jumpbox2').hide();
	$('#title').val('');
	$('#url').val('');
	$('#price').val('');
	$('#tao_img').val('');
	$('#keywords').val('');
	$('#comment').val(commentDefaultVal);
	$('#J_ImgBooth').attr('src','images/ad.jpg');
	$('#num').text(80);
}

/*这里开始时UrlEncode和UrlDecode函数*/
function UrlEncode(str){
var ret="";
var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
var tt= "";

for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
var c=str2asc(chr);
tt += chr+":"+c+"n";
if(parseInt("0x"+c) > 0x7f){
ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
}else{
if(chr==" ")
ret+="+";
else if(strSpecial.indexOf(chr)!=-1)
ret+="%"+c.toString(16);
else
ret+=chr;
}
}
return ret;
}
function UrlDecode(str){
var ret="";
for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
if(chr == "+"){
ret+=" ";
}else if(chr=="%"){
var asc = str.substring(i+1,i+3);
if(parseInt("0x"+asc)>0x7f){
ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
i+=5;
}else{
ret+=asc2str(parseInt("0x"+asc));
i+=2;
}
}else{
ret+= chr;
}
}
return ret;
}

function getTaoItem(url){
    if(url==''){
		alert('网址不能为空！');
	}
	else{
		if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
		}
		else{
			$('#J_ImgBooth').attr('src','<?=$navheadurl?>images/wait.gif');
		    $.post("<?=$navheadurl?>a.php",{'fun':'get_tao_img','url':url,'xs':'share'},function(data){//alert(data);
		        var data= eval("(" + data + ")");
				$('#radio'+data.cid).attr("checked",true);
		        $('#title').val(data.title);
				$('#price').val(data.price);
				$('#url').val(url);
			    $('#J_ImgBooth').attr('src',data.img);
				$('#tao_img').val(data.img);
			    $('#dopic').hide('normal');
				clickUrl=data.clickUrl;
				nick=data.nick;
		    });
		}
	}
}

regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
$(function(){
    $('.close').click(closeShare);
	$('#noShare').click(function(){alert('您的等级不足，不能分享宝贝！');});
	$('#startShare').click(function(){
		dduserid=<?=$_SESSION['dduserid']?$_SESSION['dduserid']:0?>;
		if(dduserid>0){
		    $('.LightBox').show();
			$('#jumpbox2').show();
			$('#jiantou').css('left','118px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#dopic').show('normal');
			$('#tao_url').val('');
		}
		else{
		    alert('登陆后才可分享商品！');
			window.location='user/login.php?url='+encodeURIComponent(location.href);
		}
	    
	});
	/*$('#url').blur(function(){
		var url=$('#url').val();
		if(url!=''){
		    getTaoItem(url);
		}
	});*/
	$('#get_tao_img').click(function(){
	    var url=$('#tao_url').val();
		var f=$(this).attr('f');
		if(f=='html'){
			getTaoItem(url);
		}
		else if(f=='jpg'){
			if(url==''){
		        alert('网址不能为空！');
	        }
			else{
			    $('#J_ImgBooth').attr('src',url);
			    $('#tao_img').val(url);
			    $('#dopic').hide('normal');
			}
		} 
	});
	$('#shaiForm').submit(function(){
        var title=$('#title').val();
		var url=$('#url').val();
		var price=$('#price').val();
		var tao_img=$('#tao_img').val();
		var keywords=jQuery.trim($('#keywords').val());
		var comment=$('#comment').val();
		//temp = comment.replace(/{.*?}/gim,""); //过滤表情字符
		var catid = $("input[name='shaicat'][type='radio']:checked").val();
        var l=keywords.split(/\s+/).length;
		var num=parseInt($('#num').text());
		var regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
		if(title==''){
		    alert('填写商品名称！');
			$('#title').focus();
		}
		else if(url==''){
		    alert('填写商品网址！');
			$('#url').focus();
		}
		else if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
			$('#url').focus();
		}
		else if(price==''){
		    alert('填写商品价格！');
			$('#price').focus();
		}
		else if(tao_img=='' || tao_img=='images/wait.gif' || tao_img=='_310x310.jpg'){
		    alert('该商品加载失败！');
			/*$('#jiantou').css('left','80px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#picFun').show();
		    $('#dopic').show('normal');*/
		}
		else if(typeof catid=='undefined'){
		    alert('选择分类');
		}
		/*else if(temp==''){
		    alert('说点什么吧，不要只发表情哦');
		}*/
		else if(num<0){
		    alert('内容超限！');
			$('#comment').focus();
		}
		else if(comment=='' || comment==commentDefaultVal){
		    alert('请添加评论内容！');
			$('#comment').focus();
		}
		else if(l>5){
		    alert('最多填写5个关键词');
			$('#keywords').focus();
		}
		else{
			$('#subShare').attr('disabled','disabled');
		    $.post("<?=$navheadurl?>a.php",{fun:'save_share',title:title,url:url,price:price,image:tao_img,keywords:keywords,comment:comment,catid:catid,'click_url':clickUrl,'nick':nick},function(data){//$('#title').val(data);
				var data= eval("(" + data + ")");
				if(data.err==0){
				    alert('提交成功');
					location.replace(location.href);//closeShare();
				}
				else{
				    alert(msgErr[data.msg]);
					$('#subShare').attr('disabled','');
				}
		    });
		}
		return false;
	});
	$('#comment').bind('focus keyup input paste',function(){  //采用几个事件来触发（已增加鼠标粘贴事件）   
	     $('#num').text(80-$(this).attr("value").length)  //获取评论框字符长度并添加到ID="num"元素上  
	});
	$('.picfunc a:not(#openem)').click(function(){
	    var left=$(this).attr('left');
		var tishi=$(this).attr('val');
		var f=$(this).attr('f');
		if(f=='jpg'){$('#tao_url').val('');}
		$('#jiantou').css('left',left);
		$('#tishi').html(tishi);
		$('#dopic').show('normal');
		$('#get_tao_img').attr('f',f);
	});
})
</script>
</head>

<body>
<?php include(DDROOTPATH.'/template/'.MOBAN.'/header.tpl.php');?>
<?php include(DDROOTPATH.'/template/'.MOBAN.'/nav.tpl.php');?>
<div class="main">
  <table class="cat" border="0" >
    <tr>
      <td <?php if($catid==''){?> class="curcat"<?php }?>><a href="baobeilist<?=$end?>">最新分享</a></td>
      <?php foreach($shaicat_arr as $k=>$v){?>
      <td <?php if($k==$catid){?> class="curcat"<?php }?>><a href="baobeilist<?=$url_head_catid?><?=$k?><?=$url_head_sort?><?=$sort?><?=$url_head_key?><?=$url_head_page?>1<?=$url_end?>"><?=$v?></a></td>
      <?php }?>
    </tr>
  </table>
  <div class="keywords" style="position:relative">
    <div <?php if($_SESSION['dduserid']>0 && $buyid==0){?> id="noShare" <?php }else{?> id="startShare"<?php }?>style="width:101px; height:27px; position:absolute; right:32px; top:46px; cursor:pointer">&nbsp;</div>
  </div>
  <div style="height:2px; overflow:hidden; background:#F0F0F0">&nbsp;</div>
  <div class="good">
    <div class="goods-top">
      <ul>
        <li <?php if($sort=='id'){?> class="cur"<?php }?>><a href="baobeilist<?=$url_head_catid?><?=$catid?><?=$url_head_sort?>id<?=$url_head_key?><?=$url_head_page?>1<?=$url_end?>">最新宝贝</a></li>
        <li <?php if($sort=='hart'){?> class="cur"<?php }?>><a href="baobeilist<?=$url_head_catid?><?=$catid?><?=$url_head_sort?>hart<?=$url_head_key?><?=$url_head_page?>1<?=$url_end?>">最热宝贝</a></li>
      </ul>
    </div>
    <!-- 产品列表 开始 -->
    <div class="goods">
    <?php if($total==0){?><div style="text-align:center; padding-top:20px; font-size:16px; color:#F00; font-weight:bold">暂无宝贝</div><?php }?>
    <div id="goods_list_img_u">
    <?php
	$shaidan_num=count($shaidan_arr);
	?>
    <?php for($j=0;$j<4;$j++){?>
    <div id="zhanxian_<?=$j+1?>" style="height:auto" class="zhanxian">
        <?php $k=$j+1; for($i=$k;$i<=$shaidan_num;$i=$i+4){$m=$i-1;?>
        <div class='zhanxian_list' style="height:auto" id="zhanxian_list_<?=$m?>">
          <li class="goods_list_img">
          <a class="img" target="_blank" href="baobei<?=$url_head_id?><?=$shaidan_arr[$m]['id']?><?=$url_end?>">
          <?=html_img($shaidan_arr[$m]['image'],$shaidan_arr[$m]['title'],'goods_list_img_i',200,'')?></a>
          <div class="pinglun">
             <div class="pinglun_s pinglun_s1" onclick="likek(<?=$shaidan_arr[$m]['id']?>)" style="cursor:pointer;" title="送红心"></div>
             <div class="pinglun_s pinglun_s2"></div>
             <div class="pinglun_s pinglun_s3" id="x_<?=$shaidan_arr[$m]['id']?>"><?=$shaidan_arr[$m]['hart']?></div>
             <div class="pinglun_s pinglun_s4"></div>
             <div class="pinglun_s pinglun_s5">
             <a class="img" style="margin-top:-13px; color:#fe5d9b; text-decoration:underline;" target="_blank" href="baobei<?=$url_head_id?><?=$shaidan_arr[$m]['id']?><?=$url_end?>#p">评论</a></div>
          </div>
          <div class="pinglun_r"></div>
          
          <div class="name" style="clear:both; width:100%; height:70px; overflow:hidden;">
          <div style="width:26px; height:26px; padding-top:8px; float:left; padding-right:5px; overflow:hidden;">
          <a href="userbao<?=$url_head_id?><?=$shaidan_arr[$m]['dduserid']?><?=$url_end?>">
          <img width="24" height="24" style="border:#ffaf9a 1px solid;" src="upload/avatar/<?=get_avatar_filepath($shaidan_arr[$m]['dduserid'], $size = 'small', $type = '')?>" />
          </a>
          </div>
          <div style=" width:150px; height:32px; padding-top:5px; line-height:16px; float:left; overflow:hidden;">
          <span style="font-size:12px; color:#e8876d;">由</span>
          <a style="color:#fe5dad;" href="userbao<?=$url_head_id?><?=$shaidan_arr[$m]['dduserid']?><?=$url_end?>"><?=$shaidan_arr[$m]['ddusername']?></a>
          <span style="font-size:12px; color:#e8876d;">分享</span><br />
          <span style=" color:#d5bba1; font-size:12px;"><?=date('m月d日 H:i',$shaidan_arr[$m]['time'])?></span>
          </div>
          <div class="comment" style="font-size:12px; color:#000; width:100%; height:25px; padding-top:5px; overflow:hidden;"><?=utf_substr(strip_tags($shaidan_arr[$m]['comment']),28)?></div>
          </div>
        </li>
        </div>
        <?php }?>
    </div>
    <?php }?>

    </div>
    
    
    
      
      <div class="megas512" style="text-align:center; margin-top:30px;"><?php pageft($total,$pagesize,1,0,0,10,$page_baobeilist);echo $pagenav;?></div>
    <div style="height:20px; width:100%"></div>
  </div>
  	<!-- 产品列表 结束 -->
   <script type="text/javascript">
    /*h=new Array();
	l=new Array();
	h[0]=0;
	for(i=1;i<=4;i++){
		h[i]=$('#zhanxian_'+i).height();
		l[i]=h[i];
		if(h[i]<h[i-1]){
		    temp=h[i-1];
		    h[i-1]=h[i];
		    h[i]=temp;
		}
	}
	for(k=1;k<=4;k++){
	    if(l[k]<h[4]){
		    $('#zhanxian_'+k).append('<div class="zhanxian_list" style=" background:url(template/<?=MOBAN?>/images/0227.png);height:'+(h[4]-l[k]-10)+'px">&nbsp;</div>');
		}
	}*/
		msg=new Array();
		msg[6]='您已经送过红心';
		msg[7]='登陆才能送红心哦';
		
		function likek(id){
			var user_hart=parseInt($("#x_"+id).text());
			$.post("a.php",{fun:'inc_hart',shai_id:id,xs:'share'},function(data){//alert(data);
				var data= eval("(" + data + ")");
				if(data.err==0){
					$("#x_"+id).text(user_hart+1);
				}
				else{
					alert(msg[data.msg]);
				}
			});
		};
    </script>
</div>
</div>
<div style="height:5px; width:100%"></div>
<?php include(DDROOTPATH.'/template/'.MOBAN.'/footer.tpl.php');?>
<div id="jumpbox2" class="jumpbox2" ><div class="top_left"></div><div class="top_center"></div><div class="top_right"></div><div class="middle_left"></div>
  <div class="middle_center">
    <div class="close"><a style="cursor:pointer"></a></div>
    <div class="w" style=" margin-top:0px; ">
    <div style="height:30px;">
    <div class="shaicat" style="margin-top:15px; margin-left:10px">
      <ul>
        <?php foreach($shaicat_arr as $k=>$v){?>
        <li><input name="shaicat" value="<?=$k?>" type="radio" id="radio<?=$k?>"> <label for="radio<?=$k?>"><?=$v?></label></li>
        <?php }?>
      </ul>
    </div>
    </div>
    <div class="form" style="width:540px; height:80px; margin-top:10px; position:relative; left:15px; z-index:999; clear:both;">
      <form id="shaiForm" style="position:relative; z-index:99">
      <div id="expression" style="left:0px">
      <ul>
		<?php foreach($expression as $k=>$v){?>
        <li><img src="<?=$navheadurl?>images/emoticons/<?=$k?>.gif" style="cursor:pointer" onclick="addExpression('comment','{<?=$v?>}');"/></li>
		<?php }?>
      </ul>
      <div style=" float:left; margin-left:2px;cursor:pointer; width:30px" onclick="$('#expression').fadeOut('slow');">关闭</div>
      </div>
        <div style="float:left; width:446px; height:62px;">
          <textarea id="comment" onfocus="if(this.value==commentDefaultVal){this.value=''};" style="width:440px; height:12px; line-height:12px; padding-top:5px; padding-bottom:40px; padding-left:4px; color:#999999; border:2px solid #F64B78"><?php if($buyid==0){?>您还没有购买商品，不能分享宝贝！<?php }else{?>说说你对这件宝贝的评价吧<?php }?></textarea>
        </div>
        <div style="float:left; margin-left:3px; width:80px; height:62px;">
          <input id="subShare" type="submit" style="background:none; border:0; font-size:18px; width:80px; height:36px; background:#EE373C; color:#FFF; font-weight:bold; cursor:pointer" value="发 布" <?php if($buyid==0){?> disabled="disabled"<?php }?>/>
        </div>
        <input type="hidden" value="" id="trade_id" />
        <input type="hidden" value="" id="tao_img" />
        <div style="clear:both"></div>
      </form>
      <div style="width:444px;margin-top:5px; position:relative;" class="picfunc">
        <div class="picfunc" style="float:left; width:300px;">
          <a onclick="$('#expression').fadeIn('slow');" left="19px" id="openem" style="background:url(images/icons.gif) no-repeat; padding-left:18px; width:57px; height:18px; line-height:18px; display:block; float:left">添加表情 | </a> 
          <a f='html' left="118px" val="在此直接粘贴宝贝的链接地址" style="background:url(images/icons.gif) no-repeat 0px -17px; padding-left:18px; width:57px; height:18px; line-height:18px; display:block; float:left; margin-left:5px">宝贝链接</a> 
         <!-- <a style="float:left; display:block; height:18px; line-height:18px; margin-left:5px" f='jpg' left="178px" val="粘贴图片的链接地址">图片链接</a>-->
        </div>
        <div style="float:right; width:130; color:#666">还可以输入<b id="num" style="font-size:14px; color:#EF363C">80</b>个字</div>
      </div>
      <div id="dopic" style="position:absolute; width:394px; height:68px; top:79px; left:0px; z-index:99; display:none">
        <div style="height:6px; overflow:hidden"><div id="jiantou" style="background:url(<?=$navheadurl?>images/icon.gif) -74px -103px; width:10px; height:6px; z-index:2; position:relative;"></div></div>
        <div style="background:url(<?=$navheadurl?>images/shai-bg.gif); width:394px; height:62px; margin-top:-1px; _margin-top:0px; z-index:1">
          <div style="position:relative; left:12px; top:12px; width:374px; height:42px">
            <div style="height:15px">
              <div style="float:left; width:200px; color:#656565" id="tishi"></div>
              <div onclick="$('#dopic').hide('normal');" style="float:right; width:12px; height:12px; background:url(<?=$navheadurl?>images/icon.gif) -56px -105px; cursor:pointer"></div>
            </div>
            <form style="height:25px; margin-top:2px">
              <div style="width:326px; float:left ">
                <input id="tao_url" type="text" style="width:324px; height:20px; border:1px solid #CFCFCF;background:#FFF; line-height:20px" />
              </div>
              <div style="float:left; height:25px; margin-left:3px;">
                <input f='html' id="get_tao_img" type="button" style="border:1px solid #CFCFCF; background:#F7F7F7; width:40px; height:24px; text-align:center; line-height:24px; color:#000; cursor:pointer" value="确定" />
              </div>
            </form>
            
          </div>
        </div>
      </div>
    </div>
    <div style="clear:both"></div>
    <div id="goodsinfo" style="margin-top:15px; margin-left:15px; width:540px; height:120px">
        <div style="float:left; width:120px;"><img id="J_ImgBooth" src="<?=$navheadurl?>images/no_news.gif" width="120" height="120" /></div>
        <div style="float:left; width:330px; height:150px; margin-left:5px">
          <div style="font-size:14px; padding-top:1px">名称：<input readonly="readonly" id="title" type="text" style=" width:250px; height:20px; border:0; line-height:20px" /></div>
          <div style="font-size:14px; padding-top:1px; margin-top:5px;">链接：<input readonly="readonly" id="url" type="text" style=" width:250px; height:20px; border:0; line-height:20px" /></div>
          <div style=" font-size:14px; padding-top:1px; margin-top:5px;">价格：<input readonly="readonly" type="text" style=" width:30px; height:20px; border:0; line-height:20px" id="price" /> 元</div>
          <div style=" font-size:14px; color:#666666; margin-top:15px;">
            <div style=" font-size:12px;"><b style="color:#333">打标签：</b>填写商品关键字，用空格隔开</div>
            <div style="margin-top:5px"><input id="keywords" type="text" style=" width:316px; height:20px; border:1px solid #9A9B9B; line-height:20px" /></div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="middle_right"></div><div class="end_left"></div><div class="end_center"></div><div class="end_right"></div></div>
</body>
</html>
